#!/bin/bash -x
#usage: ./getresults.sh <configuration file> <destination dir> <results dir>

config=$1
destdir=$2
resultsdir=$3

source $config
source export.sh $config

#initiator="root@caparcona"
#responder="root@pinta"
#mbox="root@maid"
#mbox2="root@pinta"

rm -rf ${destdir}
mkdir ${destdir}
mkdir ${destdir}/initiator
mkdir ${destdir}/responder
mkdir ${destdir}/middlebox1
mkdir ${destdir}/middlebox2

mkdir ${destdir}/eval

scp -q -P $initiator_port root@${initiator}:${resultsdir}/* ${destdir}/initiator
scp -q -P $responder_port root@${responder}:${resultsdir}/* ${destdir}/responder
scp -q -P $mbox1_port	root@${mbox1}:${resultsdir}/* ${destdir}/middlebox1
scp -q -P $mbox2_port	root@${mbox2}:${resultsdir}/* ${destdir}/middlebox2

############### INITIATOR

for f in initiator/PERF_I_HOST_CTX_LOOKUP \
         initiator/PERF_I_APP_CTX_LOOKUP \
         initiator/PERF_I_NETSTAT_LOOKUP \
         initiator/PERF_I_VERIFY_APPLICATION \
         initiator/PERF_I_X509AC_VERIFY_CERT_CHAIN \
         initiator/PERF_I_USER_CTX_LOOKUP \
         initiator/PERF_I_LOAD_USER_CERT \
         initiator/PERF_I_LOAD_USER_NAME \
         initiator/PERF_I_LOAD_USER_PUBKEY \
	 initiator/PERF_R1_VERIFY_HOST_SIG \
         initiator/PERF_I2_DH_CREATE \
         initiator/PERF_I2_SERVICE_ACK \
         initiator/PERF_I2_HANDLE_SERVICE_OFFER \
         initiator/PERF_I2_HMAC \
         initiator/PERF_I2_HOST_SIGN \
         initiator/PERF_I_LOAD_USER_KEY \
         initiator/PERF_I2_USER_SIGN \
         initiator/PERF_R2_VERIFY_HMAC \
         initiator/PERF_R2_VERIFY_HOST_SIG \
         initiator/PERF_R2_VERIFY_USER_SIG \
         initiator/PERF_TRIGGER_CONN \
         initiator/PERF_NEW_CONN \
         initiator/PERF_R1 \
         initiator/PERF_R2 \
         initiator/PERF_COMPLETE_BEX \
         initiator/PERF_IP6TABLES \
         initiator/PERF_IP6TABLES \
         initiator/PERF_CONN_REQUEST \
         initiator/PERF_HASH \
         initiator/PERF_X509AC_VERIFY_CERT_CHAIN
do
    basename=`basename "$f"`
    cp ${destdir}/${f}.csv $destdir/eval/${basename}.csv
done;

for f in PERF_HASH \
         PERF_X509AC_VERIFY_CERT_CHAIN \
         PERF_CONN_REQUEST
do
	mv ${destdir}/eval/${f}.csv $destdir/eval/${f}_I.csv
done;

############### RESPONDER

for f in responder/PERF_R_HOST_CTX_LOOKUP \
	 responder/PERF_R2_DH_CREATE \
	 responder/PERF_I2_VERIFY_HOST_SIG \
         responder/PERF_I2_VERIFY_HMAC \
         responder/PERF_I2_VERIFY_HOST_SIG \
         responder/PERF_I2_VERIFY_USER_SIG \
         responder/PERF_R_APP_CTX_LOOKUP \
         responder/PERF_R_NETSTAT_LOOKUP \
         responder/PERF_R_VERIFY_APPLICATION \
         responder/PERF_R_X509AC_VERIFY_CERT_CHAIN \
         responder/PERF_R_USER_CTX_LOOKUP \
         responder/PERF_R_LOAD_USER_CERT \
         responder/PERF_R_LOAD_USER_PUBKEY \
         responder/PERF_R_LOAD_USER_NAME \
         responder/PERF_R2_SERVICE_ACK \
         responder/PERF_R2_HANDLE_SERVICE_OFFER \
         responder/PERF_R2_HOST_SIGN \
         responder/PERF_R2_HMAC \
         responder/PERF_LOAD_USER_KEY \
         responder/PERF_R2_USER_SIGN \
         responder/PERF_NEW_CONN_RESPONDER \
         responder/PERF_HASH \
         responder/PERF_X509AC_VERIFY_CERT_CHAIN \
         responder/PERF_I1 \
         responder/PERF_I2
do
    basename=`basename "$f"`
    cp ${destdir}/${f}.csv $destdir/eval/${basename}.csv
done;

for f in PERF_HASH \
         PERF_X509AC_VERIFY_CERT_CHAIN \
         PERF_CONN_REQUEST
do
    mv ${destdir}/eval/${f}.csv $destdir/eval/${f}_R.csv
done;

############### MIDDLEBOX 1

for f in middlebox1/PERF_MBOX_R1_VERIFY_HOST_SIG \
	 middlebox1/PERF_MBOX_R1_VERIFY_WITH_POLICY \
         middlebox1/PERF_MBOX_R1_ADD_INFO_REQ \
         middlebox1/PERF_MBOX_R1_HASH_SERVICE_OFFER \
         middlebox1/PERF_MBOX_I2_VERIFY_HOST_SIG \
	 middlebox1/PERF_MBOX_I2_VERIFY_ACK \
         middlebox1/PERF_MBOX_I2_VERIFY_USER_SIG \
	 middlebox1/PERF_MBOX_I2_VERIFY_INFO_REQ \
	 middlebox1/PERF_MBOX_I2_VERIFY_WITH_POLICY \
	 middlebox1/PERF_MBOX_I2_ADD_INFO_REQ \
	 middlebox1/PERF_MBOX_I2_HASH_SERVICE_OFFER \
         middlebox1/PERF_MBOX_R2_VERIFY_HOST_SIG \
         middlebox1/PERF_MBOX_R2_VERIFY_USER_SIG \
	 middlebox1/PERF_MBOX_R2_VERIFY_ACK \
	 middlebox1/PERF_MBOX_R2_VERIFY_INFO_REQ \
         middlebox1/PERF_MBOX_I1 \
         middlebox1/PERF_MBOX_R1 \
         middlebox1/PERF_MBOX_I2 \
         middlebox1/PERF_MBOX_R2 \
         middlebox1/PERF_MBOX_I2_VERIFY_USER_PUBKEY \
         middlebox1/PERF_MBOX_R2_VERIFY_USER_PUBKEY
do
    basename=`basename "$f"`
    cp ${destdir}/${f}.csv $destdir/eval/${basename}.csv
done;

for f in PERF_MBOX_R1_VERIFY_HOST_SIG \
	 PERF_MBOX_R1_VERIFY_WITH_POLICY \
         PERF_MBOX_R1_ADD_INFO_REQ \
         PERF_MBOX_R1_HASH_SERVICE_OFFER \
         PERF_MBOX_I2_VERIFY_HOST_SIG \
	 PERF_MBOX_I2_VERIFY_ACK \
         PERF_MBOX_I2_VERIFY_USER_SIG \
	 PERF_MBOX_I2_VERIFY_INFO_REQ \
	 PERF_MBOX_I2_VERIFY_WITH_POLICY \
	 PERF_MBOX_I2_ADD_INFO_REQ \
	 PERF_MBOX_I2_HASH_SERVICE_OFFER \
         PERF_MBOX_R2_VERIFY_HOST_SIG \
         PERF_MBOX_R2_VERIFY_USER_SIG \
	 PERF_MBOX_R2_VERIFY_ACK \
	 PERF_MBOX_R2_VERIFY_INFO_REQ \
         PERF_MBOX_I1 \
         PERF_MBOX_R1 \
         PERF_MBOX_I2 \
         PERF_MBOX_R2 \
         PERF_MBOX_I2_VERIFY_USER_PUBKEY \
         PERF_MBOX_R2_VERIFY_USER_PUBKEY
do
    mv ${destdir}/eval/${f}.csv $destdir/eval/${f}_M1.csv
done;

############### MIDDLEBOX 2

for f in middlebox2/PERF_MBOX_R1_VERIFY_HOST_SIG \
	 middlebox2/PERF_MBOX_R1_VERIFY_WITH_POLICY \
         middlebox2/PERF_MBOX_R1_ADD_INFO_REQ \
         middlebox2/PERF_MBOX_R1_HASH_SERVICE_OFFER \
         middlebox2/PERF_MBOX_I2_VERIFY_HOST_SIG \
	 middlebox2/PERF_MBOX_I2_VERIFY_ACK \
         middlebox2/PERF_MBOX_I2_VERIFY_USER_SIG \
	 middlebox2/PERF_MBOX_I2_VERIFY_INFO_REQ \
	 middlebox2/PERF_MBOX_I2_VERIFY_WITH_POLICY \
	 middlebox2/PERF_MBOX_I2_ADD_INFO_REQ \
	 middlebox2/PERF_MBOX_I2_HASH_SERVICE_OFFER \
         middlebox2/PERF_MBOX_R2_VERIFY_HOST_SIG \
         middlebox2/PERF_MBOX_R2_VERIFY_USER_SIG \
	 middlebox2/PERF_MBOX_R2_VERIFY_ACK \
	 middlebox2/PERF_MBOX_R2_VERIFY_INFO_REQ \
         middlebox2/PERF_MBOX_I1 \
         middlebox2/PERF_MBOX_R1 \
         middlebox2/PERF_MBOX_I2 \
         middlebox2/PERF_MBOX_R2 \
         middlebox2/PERF_MBOX_I2_VERIFY_USER_PUBKEY \
         middlebox2/PERF_MBOX_R2_VERIFY_USER_PUBKEY
do
    basename=`basename "$f"`
    cp ${destdir}/${f}.csv $destdir/eval/${basename}.csv
done;

for f in PERF_MBOX_R1_VERIFY_HOST_SIG \
	 PERF_MBOX_R1_VERIFY_WITH_POLICY \
         PERF_MBOX_R1_ADD_INFO_REQ \
         PERF_MBOX_R1_HASH_SERVICE_OFFER \
         PERF_MBOX_I2_VERIFY_HOST_SIG \
	 PERF_MBOX_I2_VERIFY_ACK \
         PERF_MBOX_I2_VERIFY_USER_SIG \
	 PERF_MBOX_I2_VERIFY_INFO_REQ \
	 PERF_MBOX_I2_VERIFY_WITH_POLICY \
	 PERF_MBOX_I2_ADD_INFO_REQ \
	 PERF_MBOX_I2_HASH_SERVICE_OFFER \
         PERF_MBOX_R2_VERIFY_HOST_SIG \
         PERF_MBOX_R2_VERIFY_USER_SIG \
	 PERF_MBOX_R2_VERIFY_ACK \
	 PERF_MBOX_R2_VERIFY_INFO_REQ \
         PERF_MBOX_I1 \
         PERF_MBOX_R1 \
         PERF_MBOX_I2 \
         PERF_MBOX_R2 \
         PERF_MBOX_I2_VERIFY_USER_PUBKEY \
         PERF_MBOX_R2_VERIFY_USER_PUBKEY
do
    mv ${destdir}/eval/${f}.csv $destdir/eval/${f}_M2.csv
done;
